//
//  File.swift
//  
//
//  Created by 钟志远 on 2021/4/17.
//

import Foundation
import Vapor
import Fluent

final class FileModel: Model, Content {
    static var schema: String = "file"
    
    init() {}
    
    init (userId: UUID, fileNameReal: String?, fileNameShow: String, fileLength: Int) {
        self.$user.id = userId
        self.fileLength = fileLength
        self.fileNameShow = fileNameShow
        self.fileNameReal = fileNameReal
    }
    
    @ID(key: .id)
    var id: UUID?
    
    @OptionalParent(key: "parent_id")
    var parent: FileModel?
    
    @Children(for: \.$parent)
    var childFile: [FileModel]
    
    @Parent(key: "user_id")
    var user: User

    @Field(key: "is_dir")
    var isDir: Bool
    
    @OptionalParent(key: "file_type_id")
    var fileType: FileTypeModel?
    
    @OptionalField(key: "file_name_real")
    var fileNameReal: String?
    
    @Field(key: "file_name_show")
    var fileNameShow: String
    
    @Field(key: "file_length")
    var fileLength: Int
    
    @Timestamp(key: "created_at", on: .create)
    var createdAt: Date?
    
    @Timestamp(key: "updated_at", on: .update)
    var updatedAt: Date?

}
